package com.cbb.lease.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cbb.lease.mapper.BrandMapper;
import com.cbb.lease.pojo.entity.Brand;
import com.cbb.lease.pojo.vo.dataVo;
import com.cbb.lease.service.BrandService;
import com.gsj.common.pojo.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-eighth01
 * @description: 品牌接口实现类
 * @author: 陈斌斌
 * @create: 2021-07-24 15:22
 **/
@Service
public class BrandServiceImpl implements BrandService {
    @Resource
    private BrandMapper brandMapper;

    @Override
    public R getAllBrand() {
        List<Brand> brands = brandMapper.selectList(null);
        return R.ok().put("CarBrand",brands);
    }

    @Override
    public R getAllBrandPage(Integer currentPage, Integer pageSize, Brand brand) {
        Page<Brand> brandPage = new Page<>(currentPage,pageSize);
        QueryWrapper<Brand> brandQueryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(brand.getBrandName())){
            brandQueryWrapper.like("brand_name",brand.getBrandName());
        }
        Page<Brand> brandPage1 = brandMapper.selectPage(brandPage, brandQueryWrapper);
        return R.ok().put("records",brandPage1.getRecords()).put("total",brandPage1.getTotal());
    }

    @Override
    public R delById(Integer id) {
        int i = brandMapper.deleteById(id);
        return R.ok();
    }

    @Override
    public R updateBrand(Brand brand) {
        int i = brandMapper.updateById(brand);
        return R.ok();
    }

    @Override
    public R addBrand(Brand brand) {
        int insert = brandMapper.insert(brand);
        return R.ok();
    }

    @Override
    public R getEC() {
        List<dataVo> ec = brandMapper.getEC();
        return R.ok().put("vale",ec);
    }
}
